package com.zyz.bookborrowing.service;

import com.zyz.bookborrowing.bean.Student;
import com.zyz.bookborrowing.bean.User;
import com.zyz.bookborrowing.dao.IStudentDao;
import com.zyz.bookborrowing.dao.StudentDaoImpl;

import java.util.List;

public class StudentServiceImpl implements IStudentService{

    IStudentDao studentDao = new StudentDaoImpl();
    IUserService userService = new UserServiceImpl();

    @Override
    public List<Student> list(Student stu) {
        return studentDao.list(stu);
    }

    @Override
    public Integer saveStudent(Student stu) {
//        当创建一个学生信息时，同步创建账号信息
        User user = new User();
        user.setPassword("123456");
//        这里用户名用学号，密码默认123456
        user.setUsername(stu.getStuNum());
        user.setPhoneNum(stu.getPhoneNum());
        userService.addUser(user);

        return studentDao.saveStudent(stu);
    }

    @Override
    public Integer updateStudent(Student stu) {
        return studentDao.updateStudent(stu);
    }

    @Override
    public Integer deleteById(Integer id) {
        return studentDao.deleteById(id);
    }

    @Override
    public Student queryById(Integer id) {
        return studentDao.queryById(id);
    }

    @Override
    public int queryByClsId(String id) {
        return studentDao.queryByClsId(id);
    }

    @Override
    public Student queryByStuNum(String stuNum) {
        return studentDao.queryByStuNum(stuNum);
    }
}
